<template>
	<view class="content">

		<view class="top-title">
			<customNavbar title="党员信息"></customNavbar>
			<view class="top_search">
				<u-search shape="round" v-model="xm" placeholder="请输入搜索信息" @search="getMemberList" @clear="clearInfo"
					:animation="true" bg-color="#fff"></u-search>
			</view>
			<view class="main-content">
				<view class="main-content-item" v-for="item in memberList" :key="item.xm">
					<view class="name">
						<view>{{item.xm}}</view>
						<image v-if="hasAdmin"  @click="toDescribe(item.id)" class="name-img" src="../../static/images/zhishuo/编组备份.png">
						</image>
					</view>
					<view class="sex">
						<view>性别</view>
						<view class="huise">{{getDictLabel('XB',item.xb)}}</view>
					</view>
					<view class="zhongzu">
						<view>民族</view>
						<view class="huise">{{getDictLabel('MZ',item.mz)}}</view>
					</view>
					<view class="time">
						<view>入民革时间</view>
						<view class="huise">{{item.rmgsj}}</view>
					</view>
				</view>

			</view>

		</view>
	</view>
</template>

<script>
	import {
		partyMemberHomeList
	} from '../../api/index.js'
	import {
		getDictCode
	} from '../../utils/common.js'


	export default {
		data() {
			return {
				memberList: [],
				xm: '',
				timeYear: '',
				hasAdmin: uni.getStorageSync('hasAdmin')
			}
		},
		onShow() {
			this.getMemberList()
		},
		onLoad(option) {
			this.timeYear = option.year;
		},
		methods: {

			getDictLabel(dictName, code) {
				let data = uni.getStorageSync('dictData');
				let dataList = JSON.parse(data)
				const type = dataList.filter((element) => (element.dictName === dictName))
				if (type) {
					const val = type.find((element) => (element.code === code))
					if (val) {
						return val.name
					} else {
						return ''
					}
				} else {
					return ''
				}

			},
			toDescribe(id) {
				this.$common.navigateTo('/pages-dangyuan/dangyuan/dangyuan-describe?id=' + id)
			},
			clearInfo() {
				this.xm = ''
				this.getMemberList()
			},

			getMemberList() {
				partyMemberHomeList({
					year: this.timeYear,
					xm: this.xm
				}).then(res => {
					console.log(res);
					if (res.errors.length > 0) {
						uni.showToast({
							title: res.errors,
							icon: 'none',
							duration: 2000,
						});
					} else {
						this.handlerLoading = true
						this.memberList = res.result
					}

				}).catch(err => {
					console.log(err);
					this.$common.errorToShow(err)
					this.handlerLoading = false;
				})
			},


		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100%;
		width: 100%;
		background-color: #F9F9F9;
		// overflow-y: auto;

		.top-title {
			background-image: url('');
			width: 100%;
			height: vw(400);
			background-size: cover;

			.top_search {
				width: vw(686);
				margin: 0 auto;
				padding: vw(40) 0px;
			}

			.main-content {
				width: 100%;

				.main-content-item {
					width: vw(686);
					height: vw(280);
					background: #ffffff;
					border-radius: vw(16);
					box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.03);
					margin: 0 auto vw(20);

					.name {
						display: flex;
						justify-content: space-between;
						padding: vw(24) vw(20) vw(0) vw(20);
						font-size: vw(28);
						font-family: PingFang SC, PingFang SC-Semibold;
						font-weight: bold;
						text-align: left;
						color: #333333;

						.name-img {
							width: vw(40);
							height: vw(40);
						}


					}

					.sex {
						display: flex;
						justify-content: space-between;
						padding: vw(24) vw(20) vw(0) vw(20);
						font-size: vw(28);
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: Regular;
						text-align: left;
						color: #333333;

						.huise {
							color: #666666;
						}

					}

					.zhongzu {
						display: flex;
						justify-content: space-between;
						padding: vw(24) vw(20) vw(0) vw(20);
						font-size: vw(28);
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: Regular;
						text-align: left;
						color: #333333;

						.huise {
							color: #666666;
						}
					}

					.time {
						display: flex;
						justify-content: space-between;
						padding: vw(24) vw(20) vw(0) vw(20);
						font-size: vw(28);
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: Regular;
						text-align: left;
						color: #333333;

						.huise {
							color: #666666;
						}
					}
				}
			}
		}
	}
</style>
